package com.example.tiantian;

import android.app.Activity;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.view.WindowManager;
import android.widget.Toast;

public abstract class BaseActivity extends Activity {


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

        getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

        init();
        loadData();
        event();
    }

    protected abstract void init();

    protected abstract void loadData();

    protected abstract void event();

    protected void startActivity(Class<?> cls, boolean closeThisActivity) {
        startActivity(cls, null, closeThisActivity);
    }

    protected void startActivity(Class<?> cls, Bundle extras, boolean closeThisActivity) {
        Intent intent = new Intent(this, cls);
        if (extras != null) {
            intent.putExtras(extras);
        }
        startActivity(intent);
        if (closeThisActivity) {
            finish();
        }
    }

    protected void toast(String text) {
        Toast.makeText(this, text, Toast.LENGTH_SHORT).show();
    }
}
